﻿@{
    ViewBag.Title = "RptStockDetail";
}
@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>       
    <script src="@Url.Content("~/Scripts/common/gridlayout.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
@Html.Partial("~/Views/Modular/ReportsToolbar.cshtml") 
<form id="form1">
    <div id = "DivHeader" style="margin-left:0px;margin-top:0px;">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="80px" align="right">单据日期：</td>
                <td width ="220px">
                    @Html.Partial("~/Views/Modular/dxDateRangeMiniXp.cshtml") 
                </td>
                <td width ="80px" align="right">商品名称：</td>
                <td width ="200px">    
                    @Html.Partial("~/Views/Modular/LookupGoodInfo.cshtml")
                </td>
                <td width="80px" height ="32px" align="right">单据类型：</td>
                <td width="120px" height ="32px">
                    <input id="comBillType" name="comBillType" class="mini-combobox" style="width:120px;" textField="FName" valueField="FItemID" 
                    showNullItem="false" allowInput="false"/>
                    
                </td>
            </tr>
        </table>
    </div>
</form>
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                borderStyle="border:1;" url="../Report/GetStockDetail" showSummaryRow="false"
                allowCellSelect="true" allowCellEdit="true" showColumnsMenu="false" fitColumns="false"
                onrowdblclick="editBill">
                <div property="columns">
                    <div field="FDateTime" name="FDateTime" width="90" headeralign="center" allowsort="true" dateFormat="yyyy-MM-dd">日期</div>
                    <div field="FBillNo" name="FBillNo" width="130" headeralign="center" allowsort="true">单据编号</div>
                    <div field="FBillName" name="FBillName" width="90" headeralign="center" allowsort="true">摘要</div>
                    <div field="FNumber" name="FNumber" width="110" headeralign="center" allowsort="true">商品编码</div>
                    <div field="FName" name="FName" width="190" headeralign="center" allowsort="true">商品名称</div>
                    <div field="FSpec" name="FSpec" width="90" headeralign="center" allowsort="true">规格型号</div>
                    <div field="FUnitName" name="FUnitName" width="60" headeralign="center" allowsort="true">单位</div>
                    <div field="FQty" name="FQty" width="80" headeralign="center" align="right" allowsort="true" numberFormat="#,0.00">数量</div>
                    <div field="FCode" name="FCode" width="110" headeralign="center" allowsort="true">商品条码</div>                    
                </div>
            </div>
        </div>
        <div id ="summary" style="width:100%;height:50px;">
        </div>
<script>
    var sumFields = "";
    mini.parse();
    var grid = mini.get("datagrid1");
    //通用shown自动调用些方式
    function FormShown() {
        var toDay = new Date();
        mini.getbyName("FDate1").setValue(toDay);
        mini.getbyName("FDate2").setValue(toDay);
    }

    $(function () {
        LoadListComData();        
    });

    //加载分类树
    function LoadListComData() {
        var com1 = mini.get("comBillType");
        var mAppID = parent.window.getSystemAppID();
        $.post('../GetItem/GetBillType', { mjson: mAppID }, function (text) {
            com1.load(mini.decode(text).data);
            com1.select(0);
        });
    }

    function editBill() {
        var row = grid.getSelected();
        if (row) {
            var mDataType = row.FDataType;
            mDataType = parseInt(mDataType);
            switch (mDataType)
            {
                case 1:
                    parent.window.showTabByIdEx('25','InsData', '采购入库', '../Bill/InsData?datatype=1&billid=' + row.KInterID);
                    break;
                case -1:
                    parent.window.showTabByIdEx('26','InrData', '采购退货', '../Bill/InsData?datatype=-1&billid=' + row.KInterID);
                    break;
                case 2:
                    parent.window.showTabByIdEx('49','OutData', '销售出库', '../Bill/OutData?datatype=2&billid=' + row.KInterID);
                    break;
                case -2:
                    parent.window.showTabByIdEx('50','OutDataRt', '销售退货', '../Bill/OutData?datatype=-2&billid=' + row.KInterID);
                    break;
                case 3:
                    parent.window.showTabByIdEx('54','InvData', '库存调整', '../Bill/InvData?datatype=3&billid=' + row.KInterID);
                    break;
                case 4:
                    parent.window.showTabByIdEx('57','StcData', '库存盘点', '../Bill/StcData?datatype=4&billid=' + row.KInterID);
                    break;
                case 5:
                    parent.window.showTabByIdEx('77','MallData', '订单管理', '../Bill/MallData?datatype=5&billid=' + row.KInterID);
                    break;
                case 11:
                    parent.window.showTabByIdEx('83','DeliveryIn', '配送入库', '../Delivery/DeliveryIn?datatype=11&billid=' + row.KInterID);
                    break;
                case 12:
                    parent.window.showTabByIdEx('85','Delivery', '配送出库', '../Delivery/Delivery?datatype=12&billid=' + row.KInterID);
                    break;
                case 20:
                case 21:
                    parent.window.showTabByIdEx('119','DeliveryRmo', '直营配送', '../Delivery/deliveryRmo?datatype=20&billid=' + row.KInterID);
                    break;
                case 88:
                    
                    break;
                default:
                    break;
            }
        }
    }

    //加载资料列表
    function LoadData() {
        var sumList = "";
        var td1 = "";
        var td2 = "";
        var mDate1 = mini.getbyName("FDate1").getFormValue();
        var mDate2 = mini.getbyName("FDate2").getFormValue();        
        var mGoodsID = mini.getbyName("FGoodItemID").getValue();
        if ((mGoodsID == "") || (mGoodsID == "0") || (mGoodsID == undefined)) {
            mini.alert("请选择一个商品。");
            return;
        }

        var timestamp1 = new Date(mDate1).getTime();
        var timestamp2 = new Date(mDate2).getTime();

        // 计算两个时间戳之间的天数
        var days = Math.ceil(Math.abs(timestamp2 - timestamp1) / (1000 * 3600 * 24));

        if (days > 365) {
            mini.alert("时间跨度太长，请选择两个时间差在一年内的日期。");
            return;
        }

        var mBillType = mini.getbyName("comBillType").getValue();
        var sSystemAppID = parent.window.getSystemAppID();
        var mBillNo = "";
        var json = "[{";
        json = json + '"mReportType":' + '"4003",';//列表类型
        json = json + '"mSystemAppID":' + '"' + sSystemAppID + '",';
        json = json + '"mDate1":' + '"' + mDate1 + '",';
        json = json + '"mDate2":' + '"' + mDate2 + '",';
        json = json + '"mGoodsID":' + '"' + mGoodsID + '",';        
        json = json + '"mBillNo":' + '"' + mBillNo + '",';
        json = json + '"mBillType":' + '"' + mBillType + '"';        
        json = json + "}]";        
        grid.load({ mydata: json }, function (data) {
            var dataR = mini.decode(data.text);
            var iCnt = dataR.data_total.length;

            td1 = "<tr>";
            td2 = "<tr>";

            for (var i = 0; i < iCnt; i++) {
                var rw = dataR.data_total[i];

                if (i % 2 == 0) {
                    td1 += '<td width ="90px" align="right">' + rw.FBillName + ':</td>'
                        + '<td width ="80px">' + rw.FQty.toFixed(2) + '</td>';
                }
                else {
                    td2 += '<td width ="90px" align="right">' + rw.FBillName + ':</td>'
                        + '<td width ="80px">' + rw.FQty.toFixed(2) + '</td>';
                }
            }

            td1 += '</tr>';
            td2 += '</tr>';            

            sumList = td1 + td2;

            var htmlstr = '<table> ' + sumList + '</table>'
            $("#summary").html(htmlstr);
        });

        mExportDataUrl = grid.url;
        mExportDataJson = json;//导出
    }


    //搜索资料列表
    function search() {
        LoadData();
    }

</script>